package deconstruction.localization;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;

import net.minecraft.client.resources.LanguageManager;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.LanguageRegistry;
import deconstruction.common.Info;

public class LocalizationHandler {
	public static List loadedLangs = new ArrayList();


	public static void loadLanguages() {
		Properties prop = new Properties();
		URL remoteLangList = null;
		try {
			remoteLangList = new URL( "https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/%5BLangList%5D.xml" );
			InputStream listStream = remoteLangList.openStream();
			prop.loadFromXML(listStream);
		}catch (MalformedURLException e){}
		catch(IOException e){}
		loadedLangs.clear();
		for(Object key: prop.keySet()){
			loadedLangs.add( prop.getProperty((String) key));
			try {
				LanguageRegistry.instance().loadLocalization(new URL(String.format("https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/%s.xml", prop.getProperty((String)key))), prop.getProperty((String) key), true);
			} catch (Exception e) {
			}
		}
		if(!loadedLangs.contains(FMLCommonHandler.instance().getCurrentLanguage())){
			try {
				LanguageRegistry.instance().loadLocalization(new URL("https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/en_US.xml"), prop.getProperty(FMLCommonHandler.instance().getCurrentLanguage()), true);
			} catch (MalformedURLException e) {
			}
		}
	}	
}


/*
package deconstruction.localization;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.minecraft.client.resources.Language;
import net.minecraft.client.resources.LanguageManager;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.LanguageRegistry;
import deconstruction.common.Info;
import deconstruction.common.mod_Deconstruction;

public class LocalizationHandler {

	public static void loadLanguages() {
		Logger.getLogger("deconstruction").log(Level.INFO, "Retreiving remote language list...");
		Properties prop = new Properties();
		URL remoteLangList = null;
		try {
			remoteLangList = new URL( "https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/%5BLangList%5D.xml" );
			InputStream listStream = remoteLangList.openStream();
			prop.loadFromXML(listStream);
		}catch (MalformedURLException e){Logger.getLogger("deconstruction").log(Level.INFO, "Failed to get list: "+ e);}
	     catch(IOException e){Logger.getLogger("deconstruction").log(Level.INFO, "Failed to get list:"+e);}
		for(Object lang: FMLClientHandler.instance().getClient().getLanguageManager().getLanguages())
		if(prop.contains(((Language)lang).getLanguageCode())){
			try {
				LanguageRegistry.instance().
				LanguageRegistry.instance().loadLocalization(new URL(String.format("https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/%s.xml", ((Language)lang).getLanguageCode())),((Language)lang).getLanguageCode(), true);
				Logger.getLogger("deconstruction").log(Level.INFO, "Loaded localization: "+ ((Language)lang).getLanguageCode());
			} catch (Exception e) {
				Logger.getLogger("deconstruction").log(Level.WARNING, "Failed to get "+((Language)lang).getLanguageCode()+".xml");
			}
		}else{
			try {
				LanguageRegistry.instance().loadLocalization(new URL("https://dl.dropboxusercontent.com/u/118017409/lang/deconstruction/en_US.xml"), ((Language)lang).getLanguageCode(), true);
			} catch (MalformedURLException e) {}
		}

	}

}

 */